﻿using System.Linq;
using Grundy.Common;
using Grundy.Entity;
using Grundy.Message;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using FluentAssertions;

namespace Grundy.Licensing.Server.Tests
{
    [TestClass]
    public class FeatureIdentificationKeyMatcherTests
    {
        [TestMethod]
        public void Should_return_matching_feature()
        {
            var matchEvaluator = Substitute.For<FeatureIdentificationKeyMatchScoreEvaluator>();
            matchEvaluator.GetMatchScore(Arg.Any<FeatureIdentificationKey>(), Arg.Any<FeatureIdentificationKey>()).Returns(1,2,3);
            
            var matcher = new FeatureIdentificationKeyMatcher(new FeatureIdentificationKey(), matchEvaluator);
            var matchingKeys = matcher.FindMatchingKeys(Enumerable.Range(0, 2).Select(i => new FeatureIdentificationKey()));
            matchingKeys.Count.Should().Be(1);
        }

        [TestMethod]
        public void Should_not_return_matching_feature()
        {
            var matchEvaluator = Substitute.For<FeatureIdentificationKeyMatchScoreEvaluator>();
            matchEvaluator.GetMatchScore(Arg.Any<FeatureIdentificationKey>(), Arg.Any<FeatureIdentificationKey>()).Returns(0);

            var matcher = new FeatureIdentificationKeyMatcher(new FeatureIdentificationKey(), matchEvaluator);
            var matchingKeys = matcher.FindMatchingKeys(Enumerable.Range(0, 2).Select(i => new FeatureIdentificationKey()));
            matchingKeys.Count().Should().Be(0);
        }

        [TestMethod]
        public void Should_return_matching_features()
        {
            var matchEvaluator = Substitute.For<FeatureIdentificationKeyMatchScoreEvaluator>();
            matchEvaluator.GetMatchScore(Arg.Any<FeatureIdentificationKey>(), Arg.Any<FeatureIdentificationKey>()).Returns(0,1,1);

            var matcher = new FeatureIdentificationKeyMatcher(new FeatureIdentificationKey(), matchEvaluator);
            var matchingKeys = matcher.FindMatchingKeys(Enumerable.Range(0, 3).Select(i => new FeatureIdentificationKey()));
            matchingKeys.Count.Should().Be(2);
        }
    }
}
